package String类;

/**
 * @作者:侯国威
 * @时间: 2020/4/13/14:32
 * @邮箱:1045077189@qq.com 指定字符进行反转string=“abcdefgh”;
 * 方式一：先转化为char[]
 */
public class StringSort_Test {
    public static void main(String[] args) {
        StringSort_Test t1 = new StringSort_Test();
        t1.StringBuffer("abcdefgh", 1, 3);
    }
    //方式一
    public void reverse(String string, int start, int end) {

        char[] arrary = string.toCharArray();
        if (string.length() != 0) {
            for (int x = start, y = end; x < y; x++, y--) {
                char temp = arrary[x];
                arrary[x] = arrary[y];
                arrary[y] = temp;
            }
            System.out.println(arrary);
        }


    }
    //方式二

    public String StringBuffer(String string, int strat, int end){
        if (string!=null){
            String reverse=string.substring(0,strat);//切片
            for (int i = end;i>=strat;i--){
                reverse +=string.charAt(i);//拿出指定段的字符
            }
            reverse += string.substring(end+1);
            System.out.println(reverse);
        }


        return string;
    }

}
